import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:smart_devices/components/device/inventory/index.dart';
import 'package:smart_devices/ui/custom_tabbar.dart';
import 'package:smart_devices/utils/colors.dart';
import 'package:smart_devices/utils/styles.dart';

import 'list_logic.dart';

class InventoryListView extends GetView<InventoryListLogic> {
  const InventoryListView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return defaultControllerView(context);
  }

  Widget defaultControllerView(BuildContext context) {
    return DefaultTabController(
      length: controller.tabs.length,
      child: Scaffold(
        backgroundColor:
            ColorsUtils.parseColorFromHexString(ColorsUtils.colorF6f6),
        appBar: AppBar(
          leading: IconButton(
            icon: const Icon(
              Icons.arrow_back_ios,
              color: Colors.white,
              size: 15,
            ),
            onPressed: Get.back,
          ),
          automaticallyImplyLeading: false,
          title: Text(
            '设备盘点',
            style: StylesUtils.customTextStyle(
                fontSize: 18, fontWeight: FontWeight.w700),
          ),
          centerTitle: true,
          bottom: PreferredSize(
              preferredSize: const Size.fromHeight(50),
              child: Container(
                alignment: Alignment.centerLeft,
                padding: const EdgeInsets.only(top: 10),
                decoration: const BoxDecoration(color: Colors.white),
                child: Obx(() => createTab(context)),
              )),
          elevation: 0,
        ),
        body: TabBarView(
          controller: controller.tabController,
          children:
              controller.tabs.map((element) => const InventoryState()).toList(),
        ),
      ),
    );
  }

  Widget createTab(BuildContext context) {
    return ClientTabBar(
      tabs: controller.tabs
          .map((element) => Tab(
                text: element,
              ))
          .toList(),
      isScrollable: true,
      padding: EdgeInsets.zero,
      indicator: RRecTabIndicator(
        radius: 1,
        insets: const EdgeInsets.only(bottom: 5),
        color: ColorsUtils.parseColorFromHexString(ColorsUtils.color0052),
      ),
      indicatorMinWidth: 36,
      indicatorWeight: 2,
      controller: controller.tabController,
      indicatorSize: TabBarIndicatorSize.label,
      labelColor: ColorsUtils.parseColorFromHexString(ColorsUtils.color0052),
      labelStyle: StylesUtils.customTextStyle(color: ColorsUtils.color0052),
      unselectedLabelStyle:
          StylesUtils.customTextStyle(color: ColorsUtils.color3333),
      unselectedLabelColor:
          ColorsUtils.parseColorFromHexString(ColorsUtils.color3333),
    );
  }
}
